package com.sd.view;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.sd.activity.R;
import com.sd.util.BookCabin;

public class FilesAdapter extends BaseAdapter {
	private List<Map<String, Object>> mData;
	private LayoutInflater mInflater;

	public FilesAdapter(Context context,List<Map<String, Object>> data) {
		this.mInflater = LayoutInflater.from(context);
		mData = data;
	}

	public int getCount() {
		return mData.size();
	}

	public Object getItem(int arg0) {
		return null;
	}

	public long getItemId(int arg0) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.listview, null);
			holder.img = (ImageView) convertView.findViewById(R.id.img);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.info = (TextView) convertView.findViewById(R.id.info);
			holder.checkbox = (CheckBox)convertView.findViewById(R.id.checkBox);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		int img = (Integer) mData.get(position).get("img");
		if(img == R.drawable.ex_folder || img == R.drawable.files_back_btn){
			holder.checkbox.setVisibility(View.GONE);
		}else{
			holder.checkbox.setVisibility(View.VISIBLE);
			String path = (String) mData.get(position).get("info");
			if(BookCabin.getInstance().checkBookCabin(path)){
				holder.checkbox.setChecked(true);
			}else{
				holder.checkbox.setChecked(false);
			}
		}
		holder.img.setImageResource(img);
		holder.title.setText((String) mData.get(position).get("title"));
		holder.info.setText((String) mData.get(position).get("info"));
		return convertView;
	}
	
	public final class ViewHolder {
		public ImageView img;
		public TextView title;
		public TextView info;
		public CheckBox checkbox;
	}

}

